<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Cache-Control" content="no-siteapp" />

    <title>xmake v2.2.5新特性详解</title>
    <meta name="description" content="第三方包管理器支持新版本对内置的包管理进行了重构，已经支持的非常完善了，我们可以通过add_requires("libuv master", "ffmpeg", "zlib 1.20.*")`方便的安装使用依赖包，但是官方的包仓库xmake-repo目前收录的包还非常少，因此为了扩充xmake的包仓库，xmake...">

    
    <meta name="keywords" content="xmake,lua,C/C++,版本更新,远程包管理,包依赖,自动构建,tboox" /> 

    <!-- qq oauth -->
    <meta property="qc:admins" content="5211601217706727767255" />

    <!--icon -->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" sizes="192x192" href="/static/img/nice-highres.png" />
	<link rel="apple-touch-icon-precomposed" href="/static/img/apple-touch-icon-57x57-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/img/apple-touch-icon-72x72-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/img/apple-touch-icon-114x114-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/img/apple-touch-icon-144x144-precomposed.png" />
	<link rel="apple-touch-icon-precomposed" sizes="180x180" href="/static/img/retinahd_icon.png" />
	<meta name="msapplication-TileImage" content="/static/img/retinahd_icon.png" />
	
    <link rel="stylesheet" href=" /css/fontawesome/css/font-awesome.min.css ">
    <link rel="stylesheet" href=" /css/main.css ">
    <link rel="canonical" href="https://tboox.org/cn/2019/04/01/xmake-v2.2.5-new-features/">
    <link rel="alternate" type="application/rss+xml" title="TBOOX Open Source Project" href="https://tboox.org/feed.xml ">
    <link rel="alternate" hreflang="en" href="https://tboox.org/" />
    <link rel="alternate" hreflang="zh-Hans" href="https://tboox.org/cn/" />

    <!-- css -->
    <link href="/css/reward.css" rel="stylesheet" type="text/css"> 




    <script type="text/javascript">
    function isPC(){    
        var userAgentInfo = navigator.userAgent;  
        var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");    
        var flag = true;    
        for (var v = 0; v < Agents.length; v++) {    
            if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }    
        }    
        return flag;    
    }
    </script>

<!-- baidu ads -->



    <!-- baidu ads -->

</head>


  <body>

    <header id="top">
    <div class="wrapper">
        <a href="/cn" class="brand">TBOOX</a>
        <button id="headerMenu" class="menu"><i class="fa fa-bars"></i></button>
        <nav id="headerNav">
            <ul>
                <li>
                    
                    <a href="/?lang=0">
                    
                        <i class="fa fa-home"></i>English
                    </a>
                </li>

                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/project/">
                            
                        
                            <i class="fa fa-bookmark"></i>项目
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/archive/">
                            
                        
                            <i class="fa fa-archive"></i>归档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/category/">
                            
                        
                            <i class="fa fa-th-list"></i>分类
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/tag/">
                            
                        
                            <i class="fa fa-tags"></i>标记
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/docs/">
                            
                        
                            <i class="fa fa-book"></i>文档
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="https://xmake.io/#/zh-cn/about/contact" target="_blank" >
                            
                        
                            <i class="fa fa-forumbee"></i>社区
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/donation/">
                            
                        
                            <i class="fa fa-heart"></i>捐助
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                    
                    <li>
                        
                            
                            <a href="/cn/about/">
                            
                        
                            <i class="fa fa-user"></i>关于
                        </a>
                    </li>
                    
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                    
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            </ul>
        </nav>
    </div>
</header>



        <div class="page clearfix" post>
    <div class="left">
        <h1>xmake v2.2.5新特性详解</h1>
        <div class="label">

            <div class="label-card">
                <i class="fa fa-calendar"></i>2019-04-01
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
                
            </div>

            <div class="label-card">
            


<!-- <span class="point">•</span> -->
<span class="categories">
  <i class="fa fa-th-list"></i>
  
    
        <a href="/category/#xmake" title="Category: xmake" rel="category">xmake</a>
    
  

  <!-- <span class="point">•</span> -->
</span>


            </div>

            <div class="label-card">
            
<!-- <span class="point">•</span> -->
<span class="pageTag">
  <i class="fa fa-tags"></i>
  
    
        <!--a href="/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a-->
        <a href="/cn/tag/#xmake" title="Tag: xmake" rel="tag">xmake</a>&nbsp;
    
        <!--a href="/tag/#lua" title="Tag: lua" rel="tag">lua</a-->
        <a href="/cn/tag/#lua" title="Tag: lua" rel="tag">lua</a>&nbsp;
    
        <!--a href="/tag/#C%2FC%2B%2B" title="Tag: C/C++" rel="tag">C/C++</a-->
        <a href="/cn/tag/#C/C++" title="Tag: C/C++" rel="tag">C/C++</a>&nbsp;
    
        <!--a href="/tag/#%E7%89%88%E6%9C%AC%E6%9B%B4%E6%96%B0" title="Tag: 版本更新" rel="tag">版本更新</a-->
        <a href="/cn/tag/#版本更新" title="Tag: 版本更新" rel="tag">版本更新</a>&nbsp;
    
        <!--a href="/tag/#%E8%BF%9C%E7%A8%8B%E5%8C%85%E7%AE%A1%E7%90%86" title="Tag: 远程包管理" rel="tag">远程包管理</a-->
        <a href="/cn/tag/#远程包管理" title="Tag: 远程包管理" rel="tag">远程包管理</a>&nbsp;
    
        <!--a href="/tag/#%E5%8C%85%E4%BE%9D%E8%B5%96" title="Tag: 包依赖" rel="tag">包依赖</a-->
        <a href="/cn/tag/#包依赖" title="Tag: 包依赖" rel="tag">包依赖</a>&nbsp;
    
        <!--a href="/tag/#%E8%87%AA%E5%8A%A8%E6%9E%84%E5%BB%BA" title="Tag: 自动构建" rel="tag">自动构建</a-->
        <a href="/cn/tag/#自动构建" title="Tag: 自动构建" rel="tag">自动构建</a>
    
  

</span>

            </div>

        </div>
        <hr>
        <article itemscope itemtype="http://schema.org/BlogPosting">
        <h2 id="第三方包管理器支持">第三方包管理器支持</h2>

<p>新版本对内置的包管理进行了重构，已经支持的非常完善了，我们可以通过</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"libuv master"</span><span class="p">,</span> <span class="s2">"ffmpeg"</span><span class="p">,</span> <span class="s2">"zlib 1.20.*"</span><span class="p">)</span><span class="err">`</span>
</code></pre>
</div>

<p>方便的安装使用依赖包，但是官方的包仓库<a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a>目前收录的包还非常少，因此为了扩充xmake的包仓库，
xmake新增了对第三方包管理器的内置支持，通过包命名空间显式指定其他包管理器中的包，目前支持对<code class="highlighter-rouge">conan::</code>，<code class="highlighter-rouge">brew::</code>和<code class="highlighter-rouge">vcpkg::</code>包管理中的包进行安装。</p>

<h4 id="安装homebrew的依赖包">安装homebrew的依赖包</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"brew::zlib"</span><span class="p">,</span> <span class="p">{</span><span class="n">alias</span> <span class="o">=</span> <span class="s2">"zlib"</span><span class="p">}})</span>
<span class="n">add_requires</span><span class="p">(</span><span class="s2">"brew::pcre2/libpcre2-8"</span><span class="p">,</span> <span class="p">{</span><span class="n">alias</span> <span class="o">=</span> <span class="s2">"pcre2"</span><span class="p">}})</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span> 
    <span class="n">add_packages</span><span class="p">(</span><span class="s2">"pcre2"</span><span class="p">,</span> <span class="s2">"zlib"</span><span class="p">)</span>
</code></pre>
</div>

<h4 id="安装vcpkg的依赖包">安装vcpkg的依赖包</h4>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"vcpkg::zlib"</span><span class="p">,</span> <span class="s2">"vcpkg::pcre2"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span> 
    <span class="n">add_packages</span><span class="p">(</span><span class="s2">"vcpkg::zlib"</span><span class="p">,</span> <span class="s2">"vcpkg::pcre2"</span><span class="p">)</span>
</code></pre>
</div>

<p>不过需要注意的是，使用vcpkg，需要先对vcpkg与xmake进行集成才行，详细操作如下：</p>

<p>windows上用户装完vcpkg后，执行<code class="highlighter-rouge">$ vcpkg integrate install</code>，xmake就能自动从系统中检测到vcpkg的根路径，然后自动适配里面包。</p>

<p>当然，我们也可以手动指定vcpkg的根路径来支持：</p>

<div class="language-console highlighter-rouge"><pre class="highlight"><code><span class="w">$ </span><span class="nc">xmake</span><span class="kv"> f --vcpkg=f:\vcpkg
</span></code></pre>
</div>

<h4 id="安装conan的依赖包">安装conan的依赖包</h4>

<p>新版本实现了对conan的generator，来集成获取conan中的包信息，我们在xmake中使用也是非常的方便，并且可以传递conan包的所有配置参数。</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"conan::zlib/1.2.11@conan/stable"</span><span class="p">,</span> <span class="p">{</span><span class="n">alias</span> <span class="o">=</span> <span class="s2">"zlib"</span><span class="p">,</span> <span class="n">debug</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span>
<span class="n">add_requires</span><span class="p">(</span><span class="s2">"conan::OpenSSL/1.0.2n@conan/stable"</span><span class="p">,</span> <span class="p">{</span><span class="n">alias</span> <span class="o">=</span> <span class="s2">"openssl"</span><span class="p">,</span> <span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">options</span> <span class="o">=</span> <span class="s2">"OpenSSL:shared=True"</span><span class="p">}})</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span> 
    <span class="n">add_packages</span><span class="p">(</span><span class="s2">"openssl"</span><span class="p">,</span> <span class="s2">"zlib"</span><span class="p">)</span>
</code></pre>
</div>

<p>执行xmake进行编译后：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code>ruki:test_package ruki<span class="nv">$ </span>xmake
checking <span class="k">for </span>the architecture ... x86_64
checking <span class="k">for </span>the Xcode directory ... /Applications/Xcode.app
checking <span class="k">for </span>the SDK version of Xcode ... 10.14
note: try installing these packages <span class="o">(</span>pass -y to skip confirm<span class="o">)</span>?
  -&gt; conan::zlib/1.2.11@conan/stable  <span class="o">(</span>debug<span class="o">)</span>
  -&gt; conan::OpenSSL/1.0.2n@conan/stable  
please input: y <span class="o">(</span>y/n<span class="o">)</span>

  <span class="o">=</span>&gt; installing conan::zlib/1.2.11@conan/stable .. ok
  <span class="o">=</span>&gt; installing conan::OpenSSL/1.0.2n@conan/stable .. ok

<span class="o">[</span>  0%]: ccache compiling.release src/main.c
<span class="o">[</span>100%]: linking.release <span class="nb">test</span>
</code></pre>
</div>

<h2 id="内置依赖包查找支持">内置依赖包查找支持</h2>

<p>之前的版本提供了<code class="highlighter-rouge">lib.detect.find_package</code>来对依赖库进行查找，但是这需要通过import后才能使用，并且一次只能查找一个包，比较繁琐：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">on_load</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span>
        <span class="n">import</span><span class="p">(</span><span class="s2">"lib.detect.find_package"</span><span class="p">)</span>
        <span class="n">target</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="n">find_package</span><span class="p">(</span><span class="s2">"openssl"</span><span class="p">))</span>
        <span class="n">target</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="n">find_package</span><span class="p">(</span><span class="s2">"zlib"</span><span class="p">))</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>而新版本中通过内置<code class="highlighter-rouge">find_packages</code>接口，对<code class="highlighter-rouge">lib.detect.find_package</code>进行了进一步的封装，来提升易用性：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">on_load</span><span class="p">(</span><span class="k">function</span> <span class="p">(</span><span class="n">target</span><span class="p">)</span>
        <span class="n">target</span><span class="p">:</span><span class="n">add</span><span class="p">(</span><span class="n">find_packages</span><span class="p">(</span><span class="s2">"openssl"</span><span class="p">,</span> <span class="s2">"zlib"</span><span class="p">))</span>
    <span class="k">end</span><span class="p">)</span>
</code></pre>
</div>

<p>并且还支持从指定的第三方包管理器中进行查找：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">find_packages</span><span class="p">(</span><span class="s2">"conan::OpenSSL/1.0.2n@conan/stable"</span><span class="p">,</span> <span class="s2">"brew::zlib"</span><span class="p">)</span>
</code></pre>
</div>

<h2 id="参数配置依赖包安装">参数配置依赖包安装</h2>

<p>新版本中对内置的包管理进行了大规模重构和升级，并且对参数可配置编译安装依赖包进行了更好的支持，我们可以在包仓库中定义一些编译安装配置参数，来定制安装包。</p>

<p>例如, 我们以pcre2的包为例：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code>
<span class="n">package</span><span class="p">(</span><span class="s2">"pcre2"</span><span class="p">)</span>

    <span class="n">set_homepage</span><span class="p">(</span><span class="s2">"https://www.pcre.org/"</span><span class="p">)</span>
    <span class="n">set_description</span><span class="p">(</span><span class="s2">"A Perl Compatible Regular Expressions Library"</span><span class="p">)</span>

    <span class="n">set_urls</span><span class="p">(</span><span class="s2">"https://ftp.pcre.org/pub/pcre/pcre2-$(version).zip"</span><span class="p">,</span>
             <span class="s2">"ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-$(version).zip"</span><span class="p">)</span>

    <span class="n">add_versions</span><span class="p">(</span><span class="s2">"10.23"</span><span class="p">,</span> <span class="s2">"6301a525a8a7e63a5fac0c2fbfa0374d3eb133e511d886771e097e427707094a"</span><span class="p">)</span>
    <span class="n">add_versions</span><span class="p">(</span><span class="s2">"10.30"</span><span class="p">,</span> <span class="s2">"3677ce17854fffa68fce6b66442858f48f0de1f537f18439e4bd2771f8b4c7fb"</span><span class="p">)</span>
    <span class="n">add_versions</span><span class="p">(</span><span class="s2">"10.31"</span><span class="p">,</span> <span class="s2">"b4b40695a5347a770407d492c1749e35ba3970ca03fe83eb2c35d44343a5a444"</span><span class="p">)</span>

    <span class="n">add_configs</span><span class="p">(</span><span class="s2">"shared"</span><span class="p">,</span> <span class="p">{</span><span class="n">description</span> <span class="o">=</span> <span class="s2">"Enable shared library."</span><span class="p">,</span> <span class="n">default</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="s2">"boolean"</span><span class="p">})</span>
    <span class="n">add_configs</span><span class="p">(</span><span class="s2">"jit"</span><span class="p">,</span> <span class="p">{</span><span class="n">description</span> <span class="o">=</span> <span class="s2">"Enable jit."</span><span class="p">,</span> <span class="n">default</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span> <span class="nb">type</span> <span class="o">=</span> <span class="s2">"boolean"</span><span class="p">})</span>
    <span class="n">add_configs</span><span class="p">(</span><span class="s2">"bitwidth"</span><span class="p">,</span> <span class="p">{</span><span class="n">description</span> <span class="o">=</span> <span class="s2">"Set the code unit width."</span><span class="p">,</span> <span class="n">default</span> <span class="o">=</span> <span class="s2">"8"</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"8"</span><span class="p">,</span> <span class="s2">"16"</span><span class="p">,</span> <span class="s2">"32"</span><span class="p">}})</span>
</code></pre>
</div>

<p>上面我们通过<code class="highlighter-rouge">add_configs</code>定义了三个条件配置参数，使得用户在集成使用pcre2库的时候，可以定制化选择是否需要启用jit版本、bit位宽版本等，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"pcre2"</span><span class="p">,</span> <span class="p">{</span><span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">jit</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span> <span class="n">bitwidth</span> <span class="o">=</span> <span class="mi">8</span><span class="p">}})</span>
</code></pre>
</div>

<p>而且，配置参数是强约束检测的，如果传的值不对，会提示报错，避免传递无效的参数进来，像bitwidth参数配置，被限制了只能在<code class="highlighter-rouge">values = {"8", "16", "32"}</code>里面取值。</p>

<p>那么，用户如何知道我们的包当前支持哪些配置参数呢，很简单，我们可以通过下面的命令，快速查看pcre2包的所有信息：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake require --info pcre2
</code></pre>
</div>

<p>输出结果如下：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>The package info of project:
    require(pcre2): 
      -&gt; description: A Perl Compatible Regular Expressions Library
      -&gt; version: 10.31
      -&gt; urls:
         -&gt; https://ftp.pcre.org/pub/pcre/pcre2-10.31.zip
            -&gt; b4b40695a5347a770407d492c1749e35ba3970ca03fe83eb2c35d44343a5a444
         -&gt; ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.31.zip
            -&gt; b4b40695a5347a770407d492c1749e35ba3970ca03fe83eb2c35d44343a5a444
      -&gt; repo: local-repo /Users/ruki/projects/personal/xmake-repo/ 
      -&gt; cachedir: /Users/ruki/.xmake/cache/packages/p/pcre2/10.31
      -&gt; installdir: /Users/ruki/.xmake/packages/p/pcre2/10.31/23b52ca1c6c8634f5f935903c9e7ea0e
      -&gt; fetchinfo: 10.31, system, optional
          -&gt; linkdirs: /usr/local/Cellar/pcre2/10.32/lib
          -&gt; defines: PCRE2_CODE_UNIT_WIDTH=8
          -&gt; links: pcre2-8
          -&gt; version: 10.32
          -&gt; includedirs: /usr/local/Cellar/pcre2/10.32/include
      -&gt; platforms: linux, macosx
      -&gt; requires:
         -&gt; plat: macosx
         -&gt; arch: x86_64
         -&gt; configs:
            -&gt; vs_runtime: MT
            -&gt; shared: false
            -&gt; jit: true
            -&gt; bitwidth: 8
            -&gt; debug: false
      -&gt; configs:
         -&gt; shared: Enable shared library. (default: false)
         -&gt; jit: Enable jit. (default: true)
         -&gt; bitwidth: Set the code unit width. (default: 8)
            -&gt; values: {"8","16","32"}
      -&gt; configs (builtin):
         -&gt; debug: Enable debug symbols. (default: false)
         -&gt; cflags: Set the C compiler flags.
         -&gt; cxflags: Set the C/C++ compiler flags.
         -&gt; cxxflags: Set the C++ compiler flags.
         -&gt; asflags: Set the assembler flags.
         -&gt; vs_runtime: Set vs compiler runtime. (default: MT)
            -&gt; values: {"MT","MD"}
</code></pre>
</div>

<p>其中，里面的<code class="highlighter-rouge">configs:</code>部分，就是目前可提供配置的参数描述以及取值范围，而<code class="highlighter-rouge">configs (builtin):</code>中是一些xmake内置的配置参数，用户也可直接配置使用。</p>

<p>例如最常用的debug模式包：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"pcre2"</span><span class="p">,</span> <span class="p">{</span><span class="n">configs</span> <span class="o">=</span> <span class="p">{</span><span class="n">debug</span> <span class="o">=</span> <span class="kc">true</span><span class="p">}})</span>
</code></pre>
</div>

<p>由于这个太过于常用，xmake提供了更方便的配置支持：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">add_requires</span><span class="p">(</span><span class="s2">"pcre2"</span><span class="p">,</span> <span class="p">{</span><span class="n">debug</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span>
</code></pre>
</div>

<p>另外<code class="highlighter-rouge">requires:</code>里面的内容，就是当前依赖包的配置状态，方便用户查看当前使用了哪个模式的包。</p>

<h2 id="预处理模板配置文件">预处理模板配置文件</h2>

<p>xmake提供了三个新的接口api，用于在编译前，添加一些需要预处理的配置文件，用于替代<a href="https://xmake.io/#/zh/manual?id=targetset_config_header">set_config_header</a>等老接口。</p>

<ul>
  <li><code class="highlighter-rouge">add_configfiles</code></li>
  <li><code class="highlighter-rouge">set_configdir</code></li>
  <li><code class="highlighter-rouge">set_configvar</code></li>
</ul>

<p>其中<code class="highlighter-rouge">add_configfiles</code>相当于cmake中的<code class="highlighter-rouge">configure_file</code>接口，xmake中参考了它的api设计，并且在其基础上进行了扩展支持，提供更多的灵活性。</p>

<p>此接口相比以前的<code class="highlighter-rouge">set_config_header</code>更加的通用，不仅用于处理config.h的自动生成和预处理，还可以处理各种文件类型，而<code class="highlighter-rouge">set_config_header</code>仅用于处理头文件，并且不支持模板变量替换。</p>

<p>先来一个简单的例子：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"src/*.c"</span><span class="p">)</span>
    <span class="n">set_configdir</span><span class="p">(</span><span class="s2">"$(buildir)/config"</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"src/config.h.in"</span><span class="p">)</span>
</code></pre>
</div>

<p>上面的设置，会在编译前，自动的将<code class="highlighter-rouge">config.h.in</code>这个头文件配置模板，经过预处理后，生成输出到指定的<code class="highlighter-rouge">build/config/config.h</code>。</p>

<p>这个接口的一个最重要的特性就是，可以在预处理的时候，对里面的一些模板变量进行预处理替换，例如：</p>

<p>config.h.in</p>

<div class="highlighter-rouge"><pre class="highlight"><code>#define VAR1 "${VAR1}"
#define VAR2 "${VAR2}"
#define HELLO "${HELLO}"
</code></pre>
</div>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">set_configvar</span><span class="p">(</span><span class="s2">"VAR1"</span><span class="p">,</span> <span class="s2">"1"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"main.c"</span><span class="p">)</span>

    <span class="n">set_configvar</span><span class="p">(</span><span class="s2">"VAR2"</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"config.h.in"</span><span class="p">,</span> <span class="p">{</span><span class="n">variables</span> <span class="o">=</span> <span class="p">{</span><span class="n">hello</span> <span class="o">=</span> <span class="s2">"xmake"</span><span class="p">}})</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"*.man"</span><span class="p">,</span> <span class="p">{</span><span class="n">copyonly</span> <span class="o">=</span> <span class="kc">true</span><span class="p">})</span>
</code></pre>
</div>

<p>通过<a href="https://xmake.io/#/zh/manual?id=targetset_configvar">set_configvar</a>接口设置模板变量，裹着通过<code class="highlighter-rouge"><span class="p">{</span><span class="err">variables</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="err">{xxx</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="nt">""</span><span class="err">}}</span></code>中设置的变量进行替换处理。</p>

<p>预处理后的文件<code class="highlighter-rouge">config.h</code>内容为：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>#define VAR1 "1"
#define VAR2 "2"
#define HELLO "xmake"
</code></pre>
</div>

<p>而<code class="highlighter-rouge"><span class="p">{</span><span class="err">copyonly</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="err">true</span><span class="p">}</span></code>设置，会强制将<code class="highlighter-rouge">*.man</code>作为普通文件处理，仅在预处理阶段copy文件，不进行变量替换。</p>

<p>默认的模板变量匹配模式为<code class="highlighter-rouge">${var}</code>，当然我们也可以设置其他的匹配模式，例如，改为<code class="highlighter-rouge">@var@</code>匹配规则：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"config.h.in"</span><span class="p">,</span> <span class="p">{</span><span class="n">pattern</span> <span class="o">=</span> <span class="s2">"@(.-)@"</span><span class="p">})</span>
</code></pre>
</div>

<p>我们也有提供了一些内置的变量，即使不通过此接口设置，也是可以进行默认变量替换的：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>${VERSION} -&gt; 1.6.3
${VERSION_MAJOR} -&gt; 1
${VERSION_MINOR} -&gt; 6
${VERSION_ALTER} -&gt; 3
${VERSION_BUILD} -&gt; set_version("1.6.3", {build = "%Y%m%d%H%M"}) -&gt; 201902031421
${PLAT} and ${plat} -&gt; MACOS and macosx
${ARCH} and ${arch} -&gt; ARM and arm
${MODE} and ${mode} -&gt; DEBUG/RELEASE and debug/release
${DEBUG} and ${debug} -&gt; 1 or 0
${OS} and ${os} -&gt; IOS or ios
</code></pre>
</div>

<p>例如：</p>

<p>config.h.in</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cp">#define CONFIG_VERSION "${VERSION}"
#define CONFIG_VERSION_MAJOR ${VERSION_MAJOR}
#define CONFIG_VERSION_MINOR ${VERSION_MINOR}
#define CONFIG_VERSION_ALTER ${VERSION_ALTER}
#define CONFIG_VERSION_BUILD ${VERSION_BUILD}
</span></code></pre>
</div>

<p>config.h</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cp">#define CONFIG_VERSION "1.6.3"
#define CONFIG_VERSION_MAJOR 1
#define CONFIG_VERSION_MINOR 6
#define CONFIG_VERSION_ALTER 3
#define CONFIG_VERSION_BUILD 201902031401
</span></code></pre>
</div>

<p>我们还可以对<code class="highlighter-rouge">#define</code>定义进行一些变量状态控制处理：</p>

<p>config.h.in</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">FOO_ENABLE</span><span class="p">}</span>
</code></pre>
</div>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">set_configvar</span><span class="p">(</span><span class="s2">"FOO_ENABLE"</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1">-- or pass true</span>
<span class="n">set_configvar</span><span class="p">(</span><span class="s2">"FOO_STRING"</span><span class="p">,</span> <span class="s2">"foo"</span><span class="p">)</span>
</code></pre>
</div>

<p>通过上面的变量设置后，<code class="highlighter-rouge">${define xxx}</code>就会替换成：</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cp">#define FOO_ENABLE 1
#define FOO_STRING "foo"
</span></code></pre>
</div>

<p>或者（设置为0禁用的时候）</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cm">/* #undef FOO_ENABLE */</span>
<span class="cm">/* #undef FOO_STRING */</span>
</code></pre>
</div>

<p>这种方式，对于一些自动检测生成config.h非常有用，比如配合option来做自动检测：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">option</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">set_default</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
    <span class="n">set_description</span><span class="p">(</span><span class="s2">"Enable Foo"</span><span class="p">)</span>
    <span class="n">set_configvar</span><span class="p">(</span><span class="s2">"FOO_ENABLE"</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1">-- 或者传递true，启用FOO_ENABLE变量</span>
    <span class="n">set_configvar</span><span class="p">(</span><span class="s2">"FOO_STRING"</span><span class="p">,</span> <span class="s2">"foo"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"config.h.in"</span><span class="p">)</span>

    <span class="c1">-- 如果启用foo选项 -&gt; 天剑 FOO_ENABLE 和 FOO_STRING 定义</span>
    <span class="n">add_options</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span> 
</code></pre>
</div>

<p>config.h.in</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">FOO_ENABLE</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">FOO_STRING</span><span class="p">}</span>
</code></pre>
</div>

<p>config.h</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cp">#define FOO_ENABLE 1
#define FOO_STRING "foo"
</span></code></pre>
</div>

<p>关于option选项检测，以及config.h的自动生成，有一些辅助函数，可以看下：https://github.com/xmake-io/xmake/issues/342</p>

<p>除了<code class="highlighter-rouge">#define</code>，如果想要对其他非<code class="highlighter-rouge">#define xxx</code>也做状态切换处理，可以使用 <code class="highlighter-rouge">${default xxx 0}</code> 模式，设置默认值，例如：</p>

<div class="highlighter-rouge"><pre class="highlight"><code>HAVE_SSE2 equ ${default VAR_HAVE_SSE2 0}
</code></pre>
</div>

<p>通过<code class="highlighter-rouge">set_configvar("HAVE_SSE2", 1)</code>启用变量后，变为<code class="highlighter-rouge">HAVE_SSE2 equ 1</code>，如果没有设置变量，则使用默认值：<code class="highlighter-rouge">HAVE_SSE2 equ 0</code></p>

<p>关于这个的详细说明，见：<a href="https://github.com/xmake-io/xmake/issues/320">https://github.com/xmake-io/xmake/issues/320</a></p>

<h2 id="更加方便的特性检测">更加方便的特性检测</h2>

<p>我们通过<code class="highlighter-rouge">add_configfiles</code>配合option检测，可以做到检测一些头文件、接口函数、类型、编译器特性是否存在，如果存在则自动写入config.h中，例如:</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">option</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
    <span class="n">set_default</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
    <span class="n">set_description</span><span class="p">(</span><span class="s2">"Has pthread library"</span><span class="p">)</span>
    <span class="n">add_cincludes</span><span class="p">(</span><span class="s2">"pthread.h"</span><span class="p">)</span>
    <span class="n">add_cfuncs</span><span class="p">(</span><span class="s2">"pthread_create"</span><span class="p">)</span>
    <span class="n">add_links</span><span class="p">(</span><span class="s2">"pthread"</span><span class="p">)</span>
    <span class="n">set_configvar</span><span class="p">(</span><span class="s2">"HAS_PTHREAD"</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> 

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"config.h.in"</span><span class="p">)</span>
    <span class="n">add_options</span><span class="p">(</span><span class="s2">"pthread"</span><span class="p">)</span> 
</code></pre>
</div>

<p>config.h.in</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_PTHREAD</span><span class="p">}</span>
</code></pre>
</div>

<p>config.h</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cp">#define HAS_PTHREAD 1
</span></code></pre>
</div>

<p>上面的配置，我们通过option检测pthread.h里面的接口以及link库是否都存在，如果能正常使用pthread库，那么自动在config.h中定义<code class="highlighter-rouge">HAS_PTHREAD</code>，并且test target中追加上相关的links。</p>

<p>上面的option可以支持各种检测，但是配置上少许复杂繁琐了些，为了让xmake.lua更加的简洁直观，对于一些常用检测，xmake通过扩展<a href="https://xmake.io/#/zh/manual?id=includes">includes</a>接口，
提供了一些内置封装好的辅助接口函数，来快速实现上面的option检测，写入config.h的功能。</p>

<p>上面的代码我们可以简化为：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">includes</span><span class="p">(</span><span class="s2">"check_cfuncs.lua"</span><span class="p">)</span>
<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"config.h.in"</span><span class="p">)</span>
    <span class="n">configvar_check_cfuncs</span><span class="p">(</span><span class="s2">"HAS_PTHREAD"</span><span class="p">,</span> <span class="s2">"pthread_create"</span><span class="p">,</span> <span class="p">{</span><span class="n">includes</span> <span class="o">=</span> <span class="s2">"pthread.h"</span><span class="p">,</span> <span class="n">links</span> <span class="o">=</span> <span class="s2">"pthread"</span><span class="p">})</span>
</code></pre>
</div>

<p>除了<code class="highlighter-rouge">configvar_check_cfuncs</code>，我们还有<code class="highlighter-rouge">check_cfuncs</code>函数，仅吧检测结果直接在编译时候追加，不再写入configfiles文件中。</p>

<p>我们再来看个综合性的例子：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">includes</span><span class="p">(</span><span class="s2">"check_links.lua"</span><span class="p">)</span>
<span class="n">includes</span><span class="p">(</span><span class="s2">"check_ctypes.lua"</span><span class="p">)</span>
<span class="n">includes</span><span class="p">(</span><span class="s2">"check_cfuncs.lua"</span><span class="p">)</span>
<span class="n">includes</span><span class="p">(</span><span class="s2">"check_features.lua"</span><span class="p">)</span>
<span class="n">includes</span><span class="p">(</span><span class="s2">"check_csnippets.lua"</span><span class="p">)</span>
<span class="n">includes</span><span class="p">(</span><span class="s2">"check_cincludes.lua"</span><span class="p">)</span>

<span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">set_kind</span><span class="p">(</span><span class="s2">"binary"</span><span class="p">)</span>
    <span class="n">add_files</span><span class="p">(</span><span class="s2">"*.c"</span><span class="p">)</span>
    <span class="n">add_configfiles</span><span class="p">(</span><span class="s2">"config.h.in"</span><span class="p">)</span>

    <span class="n">configvar_check_ctypes</span><span class="p">(</span><span class="s2">"HAS_WCHAR"</span><span class="p">,</span> <span class="s2">"wchar_t"</span><span class="p">)</span>
    <span class="n">configvar_check_cincludes</span><span class="p">(</span><span class="s2">"HAS_STRING_H"</span><span class="p">,</span> <span class="s2">"string.h"</span><span class="p">)</span>
    <span class="n">configvar_check_cincludes</span><span class="p">(</span><span class="s2">"HAS_STRING_AND_STDIO_H"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"string.h"</span><span class="p">,</span> <span class="s2">"stdio.h"</span><span class="p">})</span>
    <span class="n">configvar_check_ctypes</span><span class="p">(</span><span class="s2">"HAS_WCHAR_AND_FLOAT"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"wchar_t"</span><span class="p">,</span> <span class="s2">"float"</span><span class="p">})</span>
    <span class="n">configvar_check_links</span><span class="p">(</span><span class="s2">"HAS_PTHREAD"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"pthread"</span><span class="p">,</span> <span class="s2">"m"</span><span class="p">,</span> <span class="s2">"dl"</span><span class="p">})</span>
    <span class="n">configvar_check_csnippets</span><span class="p">(</span><span class="s2">"HAS_STATIC_ASSERT"</span><span class="p">,</span> <span class="s2">"_Static_assert(1, \"</span><span class="err">\</span><span class="s2">");"</span><span class="p">)</span>
    <span class="n">configvar_check_cfuncs</span><span class="p">(</span><span class="s2">"HAS_SETJMP"</span><span class="p">,</span> <span class="s2">"setjmp"</span><span class="p">,</span> <span class="p">{</span><span class="n">includes</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"signal.h"</span><span class="p">,</span> <span class="s2">"setjmp.h"</span><span class="p">}})</span>
    <span class="n">configvar_check_features</span><span class="p">(</span><span class="s2">"HAS_CONSTEXPR"</span><span class="p">,</span> <span class="s2">"cxx_constexpr"</span><span class="p">)</span>
    <span class="n">configvar_check_features</span><span class="p">(</span><span class="s2">"HAS_CONSEXPR_AND_STATIC_ASSERT"</span><span class="p">,</span> <span class="p">{</span><span class="s2">"cxx_constexpr"</span><span class="p">,</span> <span class="s2">"c_static_assert"</span><span class="p">},</span> <span class="p">{</span><span class="n">languages</span> <span class="o">=</span> <span class="s2">"c++11"</span><span class="p">})</span>
</code></pre>
</div>

<p>config.h.in</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_STRING_H</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_STRING_AND_STDIO_H</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_WCHAR</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_WCHAR_AND_FLOAT</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_PTHREAD</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_STATIC_ASSERT</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_SETJMP</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_CONSTEXPR</span><span class="p">}</span>
<span class="err">$</span><span class="p">{</span><span class="n">define</span> <span class="n">HAS_CONSEXPR_AND_STATIC_ASSERT</span><span class="p">}</span>
</code></pre>
</div>

<p>config.h</p>

<div class="language-c highlighter-rouge"><pre class="highlight"><code><span class="cm">/* #undef HAS_STRING_H */</span>
<span class="cp">#define HAS_STRING_AND_STDIO_H 1
</span><span class="cm">/* #undef HAS_WCHAR */</span>
<span class="cm">/* #undef HAS_WCHAR_AND_FLOAT */</span>
<span class="cp">#define HAS_PTHREAD 1
#define HAS_STATIC_ASSERT 1
#define HAS_SETJMP 1
</span><span class="cm">/* #undef HAS_CONSTEXPR */</span>
<span class="cp">#define HAS_CONSEXPR_AND_STATIC_ASSERT 1
</span></code></pre>
</div>

<p>可以看到，xmake还提供了其他的辅助函数，用于检测：c/c++类型，c/c++代码片段，c/c++函数接口，链接库，头文件是否存在，甚至是c/c++编译器特性支持力度等。</p>

<p>关于这块的更加完整的说明，可以看下：<a href="https://github.com/xmake-io/xmake/issues/342">https://github.com/xmake-io/xmake/issues/342</a></p>

<h2 id="配置自定义安装文件">配置自定义安装文件</h2>

<p>对于<code class="highlighter-rouge">xmake install/uninstall</code>命令，xmake新增了<code class="highlighter-rouge">add_installfiles</code>接口来设置一些安装文件，比起<code class="highlighter-rouge">on_install</code>，此接口用起来更加的方便简洁，基本能够满足大部分安装需求。</p>

<p>比如我们可以指定安装各种类型的文件到安装目录：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_installfiles</span><span class="p">(</span><span class="s2">"src/*.h"</span><span class="p">)</span>
    <span class="n">add_installfiles</span><span class="p">(</span><span class="s2">"doc/*.md"</span><span class="p">)</span>
</code></pre>
</div>

<p>默认在linux等系统上，我们会安装到<code class="highlighter-rouge">/usr/local/*.h, /usr/local/*.md</code>，不过我们也可以指定安装到特定子目录：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_installfiles</span><span class="p">(</span><span class="s2">"src/*.h"</span><span class="p">,</span> <span class="p">{</span><span class="n">prefixdir</span> <span class="o">=</span> <span class="s2">"include"</span><span class="p">})</span>
    <span class="n">add_installfiles</span><span class="p">(</span><span class="s2">"doc/*.md"</span><span class="p">,</span> <span class="p">{</span><span class="n">prefixdir</span> <span class="o">=</span> <span class="s2">"share/doc"</span><span class="p">})</span>
</code></pre>
</div>

<p>上面的设置，我们会安装到<code class="highlighter-rouge">/usr/local/include/*.h, /usr/local/share/doc/*.md</code></p>

<p>我们也可以通过<code class="highlighter-rouge">()</code>去提取源文件中的子目录来安装，例如：</p>

<div class="language-lua highlighter-rouge"><pre class="highlight"><code><span class="n">target</span><span class="p">(</span><span class="s2">"test"</span><span class="p">)</span>
    <span class="n">add_installfiles</span><span class="p">(</span><span class="s2">"src/(tbox/*.h)"</span><span class="p">,</span> <span class="p">{</span><span class="n">prefixdir</span> <span class="o">=</span> <span class="s2">"include"</span><span class="p">})</span>
    <span class="n">add_installfiles</span><span class="p">(</span><span class="s2">"doc/(tbox/*.md)"</span><span class="p">,</span> <span class="p">{</span><span class="n">prefixdir</span> <span class="o">=</span> <span class="s2">"share/doc"</span><span class="p">})</span>
</code></pre>
</div>

<p>我们把<code class="highlighter-rouge">src/tbox/*.h</code>中的文件，提取<code class="highlighter-rouge">tbox/*.h</code>子目录结构后，在进行安装：<code class="highlighter-rouge">/usr/local/include/tbox/*.h, /usr/local/share/doc/tbox/*.md</code></p>

<p>当然，用户也可以通过<a href="https://xmake.io/#/zh/manual?id=targetset_installdir">set_installdir</a>接口，来配合使用。</p>

<p>关于此接口的详细说明，见：https://github.com/xmake-io/xmake/issues/318</p>

<h2 id="cmakeliststxt导出">CMakelists.txt导出</h2>

<p>新版本对<code class="highlighter-rouge">xmake project</code>工程生成插件进行了扩展，新增了对CMakelists.txt文件的导出支持，方便使用xmake的用户可以快速导出CMakelists.txt提供给cmake，
以及CLion等一些支持cmake的工具使用，使用方式如下：</p>

<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>xmake project -k cmakelists
</code></pre>
</div>

<p>即可在当前工程目录下，生成对应的CMakelists.txt文件。</p>

<h2 id="更多新特性改进">更多新特性改进</h2>

<p>请详见：https://github.com/xmake-io/xmake/releases/tag/v2.2.5</p>

        </article>
        <hr>

        <!-- baidu ads -->
        

        <!-- reward -->
        <div style="text-align: center;">
            <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
              <span>赏</span>
            </button>
            <div id="QR" style="display: none;">
                <div id="wechat" style="display: inline-block">
                  <img id="wechat_qr" src="/static/img/weixin.png" alt="WeChat Pay"/>
                  <p>微信打赏</p>
                </div>
                <div id="alipay" style="display: inline-block">
                  <img id="alipay_qr" src="/static/img/alipay.png" alt="Alipay"/>
                  <p>支付宝打赏</p>
                </div>
            </div>
        </div>

        
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
                    
                    <h2 id="english">English</h2>
                    <ul>
                    
                    <li class="relatedPost">
                        <a href="/2019/04/01/xmake-v2.2.5-new-features/">Introduction of xmake v2.2.5 new features
                        
                        </a>
                    </li>
                    
                    
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
            
            
                
            
        
            
        
        
            </ul>
        

        
        
            
        
            
            
            
                
                    
                        
                        <h2 id="similar_posts">相关文章</h2>
                        <ul>
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/17/xmake-update-v2.6.2/">xmake v2.6.2 发布，新增 Linux 内核驱动模块构建支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/12/03/xmake-update-v2.6.1/">xmake v2.6.1 发布，使用 Lua5.4 运行时，Rust 和 C++ 混合编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/30/xmake-update-v2.5.9/">xmake v2.5.9 发布，改进 C++20 模块，并支持 Nim, Keil MDK 和 Unity Build
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/10/08/xmake-update-v2.5.8/">xmake v2.5.8 发布，新增 Pascal/Swig 程序和 Lua53 运行时支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
            
        
            
            
            
                
                    
                        
                        <li class="relatedPost">
                            <a href="/cn/2021/08/29/xmake-update-v2.5.7/">xmake v2.5.7 发布，包依赖锁定和 Vala/Metal 语言编译支持
                            
                            </a>
                        </li>
                        
                        
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
                    
                
            
            
        
        
            </ul>
        

        <div class="post-recent">
    <div class="pre">

        

        

        
        
        

        

        

        
        
        <p><strong>上一篇</strong> <a href="/cn/2019/03/29/xmake-update-v2.2.5/">xmake v2.2.5, 更加完善的包依赖管理</a></p>
        
    </div>

    <div class="nex">

        

        

        
        
        

        

        

        
        
        <p><strong>下一篇</strong> <a href="/cn/2019/05/26/xmake-update-v2.2.6/">xmake v2.2.6 发布, Qt/Android编译支持</a></p>
        
    </div>
</div>


        <h2 id="comments">评论</h2>
        






<div id="gitalk-container"></div>
<link rel="stylesheet" href="/css/gitalk.css">
<script src="/js/gitalk.min.js"></script>

<script>
const gitalk = new Gitalk({
  clientID: '73946dc1d9e2276ad0da',
  clientSecret: '12a3cb94361ba3ebc6ecb68cf80d592bfaa8106d',
  repo: 'tboox.github.io',
  owner: 'waruqi',
  admin: ['waruqi'],
  id: location.pathname,       
  language: 'zh-CN',
  distractionFreeMode: false  
})

gitalk.render('gitalk-container')
</script>





    </div>
    <button class="anchor"><i class="fa fa-anchor"></i></button>
    <div class="right">
        <div class="wrap">

            <!-- codefund ads -->
            

            <!-- Content -->
            <div class="side content">
                <div>
                    内容
                </div>
                <ul id="content-side" class="content-ul">
                    <li><a href="#english">English</a></li>
                    <li><a href="#similar_posts">相关文章</a></li>
                    <li><a href="#comments">评论</a></li>
                </ul>
            </div>


            <!-- baidu ads -->
            
            
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    链接
                </div>
                <ul class="content-ul">
                  <li><a href="http://github.com/waruqi/tbox">tbox</a></li>
                  <li><a href="http://www.xmake.io">xmake</a></li>
                  <li><a href="https://github.com/waruqi">github</a></li>
                </ul>
            </div> 

            <!-- xmake courses -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    xmake 入门课程
                </div>
                <a href="https://xmake.io/#/zh-cn/about/course" target="_blank">
                <img src="/static/img/xmake-course.png" alt="course" width="256" height="193">
                </a>
            </div>

            <!-- qqgroup -->
            <br>
            <div class="side">
                <div>
                    <i class="fa fa-external-link"></i>
                    技术交流群（QQ）
                </div>
                <img src="/static/img/qqgroup.png" alt="qqgroup" width="256" height="284">
            </div> 

            <!-- google ads -->
            

            <!-- baidu ads -->
            

        </div>
    </div>

    <!-- baidu ads -->
    
</div>
<script>
/**
 * target _blank
 */
(function() {
    var aTags = document.querySelectorAll('article a:not([id])')
    for (var i = 0; i < aTags.length; i++) {
        aTags[i].setAttribute('target', '_blank')
    }
}());
</script>
<script src="/js/pageContent.js " charset="utf-8"></script>



    <footer class="site-footer">
    <div class="wrapper">
        <p class="description">
             Copyright (c) 2016-2020 tboox.org 
        </p>
        <p class="contact">
            
            <a href="https://github.com/waruqi" title="GitHub"><i class="fa fa-github" aria-hidden="true"></i></a> 
             
            
            <a href="mailto:waruqi@gmail.com" title="email"><i class="fa fa-envelope-o" aria-hidden="true"></i></a> 
            
            
            <a href="https://twitter.com/waruqi" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a> 
            
            <a href="/feed.xml" title="feed"><i class="fa fa-feed" aria-hidden="true"></i></a> 
        </p>
        <p class="power">
            <span>
                Site powered by <a href="https://jekyllrb.com/">Jekyll</a> & <a href="https://github.com/Gaohaoyang">HyG</a> & <a href="https://pages.github.com/">Github Pages</a>.
            </span>
        </p>
    </div>
</footer>

    <div class="back-to-top">
    <a href="#top" class="scroll">
        <i class="fa fa-arrow-up" aria-hidden="true"></i>
    </a>
</div>

    <script src=" /js/main.js " charset="utf-8"></script>
    <script src=" /js/scroll.min.js " charset="utf-8"></script>
  </body>

</html>
